import numpy as np
import matplotlib.pyplot as plt
# 生成数据
x = np.array([1, 2, 3, 4, 5, 6, 7])
y = np.array([3, 5, 7, 9, 11, 16, 16])


# 计算斜率和截距
slope, intercept = np.polyfit(x, y, 1)

print('Slope:', slope)
print('Intercept:', intercept)

# # 绘制散点图
# plt.scatter(x, y)
#
# plt.title('Scatter Plot')
# plt.xlabel('X')
# plt.ylabel('Y')
#
# plt.show()

# 绘制散点图
plt.scatter(x, y)

# 绘制回归线
y = slope*x + intercept
plt.plot(x, y, color='r')

plt.title('Linear Regression')
plt.xlabel('X')
plt.ylabel('Y')

plt.show()



